package com.boang.config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @author 13813
 */
public class StorageCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map<String, Object> attrs = metadata.getAnnotationAttributes(
                ConditionalOnStorage.class.getName());
        String expectedType = (String) attrs.get("type");
        String activeType = context.getEnvironment()
                .getProperty("storage.active");
        return expectedType.equalsIgnoreCase(activeType);
    }
}

